<?php
declare (strict_types=1);

namespace Plugin\Organization\Model;

use App\Model\Permission\User;
use Mine\MineModel;

class RdOrganizeUser extends MineModel
{
    /**
     * The table associated with the model.
     *
     * @var string|null
     */
    protected ?string $table = 'rd_organize_user';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected array $fillable = [
        'id', 'user_id', 'enterprise_id', 'wechat_openid', 'extra_data', 'department', 'position', 'created_at', 'updated_at', 'created_by', 'updated_by', 'remark'
    ];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected array $casts = [
        'id' => 'integer',
        'user_id' => 'integer',
        'enterprise_id' => 'integer',
        'extra_data' => 'json',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    /**
     * 关联企业
     */
    public function enterprise()
    {
        return $this->belongsTo(RdOrganizeEnterprise::class, 'enterprise_id');
    }

    /**
     * 关联用户
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }
}